#!/bin/bash
#参考地址 https://docs.docker.com/engine/install/centos/
rpm -q yum &>/dev/null
if [ $? -ne 0 ]; then
    echo "请先安装yum工具"
    exit
fi
#需要卸载任何冲突的软件包
yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine -y

rpm -q wget &>/dev/null
if [ $? -ne 0 ]; then
    yum install wget -y
fi
rpm -q yum-utils &>/dev/null
if [ $? -ne 0 ]; then
    yum install yum-utils -y
fi
#更换为阿里云(下载的目录地址-/etc/yum.repos.d/docker-ce.repo)
#https://download.docker.com/linux/centos/docker-ce.repo 官网提供地址
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#出现指定的rmp下载不了的情况替换镜像源(直接修改文件docker-ce.repo) mirrors.ustc.edu.cn/docker-ce|mirrors.aliyun.com/docker-ce 或其他可用源即可
#安装社区版
yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
#设置开机启动
systemctl enable --now docker
#启动docker
systemctl start docker
#设置镜像
if [ ! -d "/etc/docker" ]; then
    mkdir -p  /etc/docker
fi

tee /etc/docker/daemon.json <<-'EOF'
{
    "registry-mirrors": [
     "https://docker.m.daocloud.io",
     "https://docker.imgdb.de",
     "https://docker-0.unsee.tech",
     "https://docker.hlmirror.com",
     "https://docker.1ms.run",
     "https://func.ink",
     "https://lispy.org",
     "https://docker.xiaogenban1993.com",
     "https://docker.xuanyuan.me",
	 "http://docker.zhai.cm",
     "https://docker.registry.cyou",
     "https://docker-cf.registry.cyou",
     "https://dockercf.jsdelivr.fyi",
     "https://docker.jsdelivr.fyi",
     "https://dockertest.jsdelivr.fyi",
     "https://mirror.aliyuncs.com",
     "https://dockerproxy.com",
     "https://mirror.baidubce.com",
     "https://docker.nju.edu.cn",
     "https://docker.mirrors.sjtug.sjtu.edu.cn",
     "https://docker.mirrors.ustc.edu.cn",
     "https://mirror.iscas.ac.cn",
     "https://docker.rainbond.cc",
     "http://noohub.ru",
     "http://docker.nastool.de",
     "http://hub.docker-ttc.xyz",
     "http://freeno.xyz",
     "http://docker.hpcloud.cloud",
     "http://dislabaiot.xyz",
     "http://docker.wget.at",
     "http://lynn520.xyz",
     "http://dockerproxy.com",
     "http://hub.xdark.top",
     "http://hub.yuzuha.cc",
     "http://docker.nat.tf",
     "http://hub.firefly.store",
     "http://hub.littlediary.cn",
     "http://ccr.ccs.tencentyun.com",
     "http://docker.kejilion.pro",
     "http://registry.dockermirror.com",
     "http://docker.mrxn.net",
     "http://dhub.kubesre.xyz",
     "http://docker.hlyun.org",
     "http://hub.rat.dev",
     "http://dockerproxy.cn",
     "http://dockerpull.org",
     "http://hub.xdark.top",
     "http://hub.littlediary.cn",
     "http://docker.udayun.com",
     "http://docker.1panel.dev",
     "http://docker.fxxk.dedyn.io",
     "http://docker.xn--6oq72ry9d5zx.cn",
     "http://docker.m.daocloud.io",
     "http://a.ussh.net",
     "http://docker.zhai.cm"
    ]
}
EOF
# 重新启动
systemctl daemon-reload && sudo systemctl restart docker
# 拉取一个测试镜像
docker pull hello-world
# 查看镜像
docker image ls -a

## 删除

#1,yum remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras -y
#2,rm -rf /var/lib/docker
#3,rm -rf /var/lib/containerd